<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Gass_message extends CI_Controller { 
    function __construct() 
    {
        parent::__construct();
 		
		// To load the CI benchmark and memory usage profiler - set 1==1.
		if (1==2) 
		{
			$sections = array(
				'benchmarks' => TRUE, 'memory_usage' => TRUE, 
				'config' => FALSE, 'controller_info' => FALSE, 'get' => FALSE, 'post' => FALSE, 'queries' => FALSE, 
				'uri_string' => FALSE, 'http_headers' => FALSE, 'session_data' => FALSE
			); 
			$this->output->set_profiler_sections($sections);
			$this->output->enable_profiler(TRUE);
		}
		
		// Load required CI libraries and helpers.
		$this->load->database();
 		$this->load->helper('url');
 		$this->load->helper('form');

  		// IMPORTANT! This global must be defined BEFORE the flexi auth library is loaded! 
 		// It is used as a global that is accessible via both models and both libraries, without it, flexi auth will not work.
		$this->auth = new stdClass;

		// Load 'standard' flexi auth library by default.
		$this->load->library('flexi_auth');	

    $this->config->load('gass_conf');
		// Note: This is only included to create base urls for purposes of this demo only and are not necessarily considered as 'Best practice'.
		$this->load->vars('base_url', $this->config->item('base_url'));
		$this->load->vars('includes_dir', $this->config->item('includes_dir'));
		$this->load->vars('current_url', $this->uri->uri_to_assoc(1));
		
		// Define a global variable to store data that is then used by the end view page.
		$this->data = null;
		//$this->output->enable_profiler(TRUE);
	  }
	  
 	/**
 	 * 用户的站内信数据聚合页面
 	 *
 	 * 根据用户ID获取该用户的站内信列表，并支持向各招生二级单位快速发送站内信
 	 * 内容分页、搜索：
 	 */
 	 function message_list($uId)
 	 { 	 	
		 $this->load->model('gass_message_model');
		 if($this->input->post('search_text'))
		 {
		 	$search_query = str_replace(' ','-',$this->input->post('search_text'));
		 	redirect('gass_message/message_list/'.$uId.'/search/'.urlencode($search_query));
		 }
		 $this->gass_message_model->get_message_list($uId);  	
		 $this->data['uId'] = $uId;
		 $this->data['college_teacher_array'] = $this->gass_global_model->get_college_teacher_list(); 
		 $this->data['message'] = $this->session->flashdata('message');
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
		 $this->load->view('gass_message/mess_list_view', $this->data);
 	 }
 	/**
 	 * message_session
 	 * 根据会话双方的ID获取双方的交谈记录
 	 */
 	 function message_session($fId,$sId){
 	 	
		 $this->load->model('gass_message_model');
		 $this->gass_message_model->message_session($fId,$sId); 	 	
		 
		 $this->data['message'] = $this->session->flashdata('message');
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
		 $this->load->view('gass_message/mess_session_view', $this->data);
 	 }
 	/**
 	 * send_message ()
 	 * 像特定用户发送站内信
 	 */
 	 function send_message(){
 	 	
		 $this->load->model('gass_message_model');
		 $this->gass_message_model->new_message( $this->flexi_auth->get_user_id() , $_POST['recId'], $_POST['text']); 	 	 	
 			 
		 //$this->data['message'] = $this->session->flashdata('message');
		 //$this->load->view('gass_message/message_list_view', $this->data);
 	 }
 	/**
 	 * session_del
 	 * 根据会话双方的ID设置相应的信息未过期
 	 * 思路：当当前用户为发送者或接收者时，置相应的发送或接收状态为过期
 	 */
 	 function session_del($fId,$sId){
		 $this->load->model('gass_message_model');
		 $this->gass_message_model->session_del($fId,$sId);  	 	 
 	 }
}
